package com.example.test.service.impl;

import com.example.test.mapper.StyleMapper;
import com.example.test.mapper.TempItemsMapper;
import com.example.test.mapper.TempsMapper;
import com.example.test.service.TempService;
import com.example.test.vo.PrintTemplatesVO;
import com.example.test.vo.TempItemsVO;
import com.example.test.vo.TempStyleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TempServiceImpl implements TempService {
    @Autowired
    private TempItemsMapper itemsMapper;
    @Autowired
    private StyleMapper styleMapper;
    @Autowired
    private TempsMapper tempsMapper;

    @Override
    public void save(List<PrintTemplatesVO> tempList) {

        tempsMapper.save(tempList);
        tempList.forEach(temp->{
            List<TempItemsVO> tempItems = temp.getTempItems();

            tempItems.forEach(items->{
                items.setTempId(temp.getId());
                itemsMapper.save(tempItems);

                TempStyleVO style = items.getStyle();
                style.setItemId(items.getId());
                styleMapper.save(style);
            });
        });
    }

    @Override
    public List<PrintTemplatesVO> listAll() {
        return tempsMapper.listAll();
    }
}
